package org.jeecg;

import java.io.FileOutputStream;
import java.io.IOException;

public class Main {

    // 将十六进制字符串转换为字节数组
    private static byte[] hexStringToBytes(String hexStr) {
        if (hexStr.length() % 2 != 0) {
            throw new IllegalArgumentException("Hex string length must be even.");
        }

        int len = hexStr.length();
        byte[] bytes = new byte[len / 2];

        for (int i = 0; i < len; i += 2) {
            bytes[i / 2] = (byte) Integer.parseInt(hexStr.substring(i, i + 2), 16);
        }

        return bytes;
    }

    public static void main(String[] args) {
        // 示例十六进制数据
        String hexData = "FF"; // 十六进制数据

        byte[] bytes = hexData.getBytes();

        for (byte aByte : bytes) {
            System.out.println(aByte);
        }

        System.out.println(bytes);
        try {

        } catch (IllegalArgumentException e) {
            System.err.println("Error: " + e.getMessage());
            return;
        }

        // 写入二进制文件
        try (FileOutputStream fos = new FileOutputStream("output.bin")) {
            fos.write(bytes);
            System.out.println("Binary file generated: output.bin");
        } catch (IOException e) {
            System.err.println("Error writing file: " + e.getMessage());
        }
    }
}
